from sqlmodel import SQLModel, Field
from datetime import date, datetime
from enum import Enum

class RunStatus(str, Enum): RUNNING = 'R'; DONE = 'D'

class BacktestRun(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    name: str
    start_date: date
    end_date: date
    init_cash: float = 1e6
    status: RunStatus = RunStatus.RUNNING
    created_at: datetime = Field(default_factory=datetime.utcnow)

class DailyPnl(SQLModel, table=True):
    run_id: int = Field(foreign_key="backtestrun.id", primary_key=True)
    trade_date: date = Field(primary_key=True)   # 改名：trade_date
    nav: float
    pnl: float
    drawdown: float
    sharpe: float
